#!/usr/bin/env python
# coding: utf-8

from PyQt5 import QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import  *
import sys


class Calendar(QWidget):

    date_signal = pyqtSignal(list)

    def __init__(self, tmp):
        super(Calendar, self).__init__()
        self.setWindowTitle("日历")
        # self.move(300,300)
        self.resize(300,200)
        self.center()
        self.cal = QCalendarWidget(self)
        self.cal.setGridVisible(True)
        self.cal.clicked.connect(self.show_date)
        self.vbox = QVBoxLayout()
        self.vbox.addWidget(self.cal)
        self.setLayout(self.vbox)
        self.tmp = tmp

    def show_date(self):
        date = self.cal.selectedDate()
        # tmp = self.tmp
        list_rslt = [self.tmp, date]
        self.date_signal.emit(list_rslt)
        self.close()

    def center(self):
        self.screen = QDesktopWidget().screenGeometry()
        self.size = self.geometry()
        self.move((self.screen.width() - self.size.width())/2,
                  (self.screen.height() - self.size.height())/2
                  )
